package distribution

import (
	"activity_srv/activityclient"
	"api/internal/respons"
	"api/internal/svc"
	"api/internal/types"
	"context"

	"github.com/zeromicro/go-zero/core/logx"
)

type SetDistributionUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewSetDistributionUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *SetDistributionUserLogic {
	return &SetDistributionUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// SetDistributionUser 设置分销用户
func (l *SetDistributionUserLogic) SetDistributionUser(req *types.SetDistributionUserRequest) (resp *types.Response, err error) {
	user, err := l.svcCtx.ActivityRpc.SetDistributionUser(l.ctx, &activityclient.SetDistributionUserRequest{
		UserId:      req.UserId,
		ParentId:    req.ParentId,
		TotalIncome: req.TotalIncome,
		Available:   req.Available,
		Frozen:      req.Frozen,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}

	return respons.Success(user), nil
}
